/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%	
% generate hypothesis space for examples
%	1. get one example by index;
%	2. output a bunch of Ts
%	--only T(ID is useless after reconstruction)
%	--duplicate removed

WORK OR NOT:
Top Theory
DepthLimit (Peano number)

This file is just findall -- all predicate is just for wrapping 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

% this g can be adapted to different 
g(EI,Ts):-
	%tell('hypothesesGenTest.txt'),
	singleE(EI,Ts),
	%numbersList(From,To,EIs),
	%allEs(DepthLimit,EIs,Ts),

	length(Ts,K), write(K),	
	%Ts=Ts1, %
	Ts=Ts1, %remove_duplicates(Ts,Ts1),
 length(Ts1,K1), write(' Duplicate removed, then remain:  '), write(K1),% in case of no duplicates--then no remove_duplicate to save time
	%write(' HYPOSESE have been obtained and they are '),nl,
	nl %, print_list(Ts)
	.
	%, told.






/*************** Single-Example Seed ***************/
% single E -> Ts
/*singleE(EI,RecordAll):-
	set(depthLimit,DepthLimit),
	findall(OneTr,
		(
			gEx(DepthLimit,EI,OneTr0)
		%portray_clause(candidateH(EI,OneTr))
		%,write('*** One candidate Hypothesis'),write(OneTr),nl
		, OneTr0=OneTr %
		%,remove_duplicates(OneTr0,OneTr),
		%tInterpreter(OneTr,T),print_list(T),nl,
		%,write('*** One theory'),nl,
		%write(OneTr),nl,	% track the ID of clauses in B		
		%nl	 
		),
		RecordAll).*/

singleE(EI,RecordAll):-
	(set(constraint,sameChange_alongTimes) ->
		sameChange_alongTime(EI); % the Answer consist of yes/ no-same/diff
		Foo=0 % do nothing
	),
	(set(constraint,sameChange_acrossMutants)->
		checkSameChange_acrossMutant(EI);
		Foo=0
	),
	set(depthLimit,DepthLimit),
	findall(OneTr,
		(
			gEx(DepthLimit,EI,OneTr0)
		%portray_clause(candidateH(EI,OneTr))
		%,write('*** One candidate Hypothesis'),write(OneTr),nl
		, OneTr0=OneTr %
		%,remove_duplicates(OneTr0,OneTr),
		%tInterpreter(OneTr,T),print_list(T),nl,
		%,write('*** One theory'),nl,
		%write(OneTr),nl,	% track the ID of clauses in B		
		%nl	 
		),
		RecordAll),
	retractall(flag_sameChange_acrossMutants(on)),
	retractall(flag_sameChange_alongTimes(on)).




/*************** Multi-Example Seed ***************/
% please notice here has been changed to accommodate.
multiE(EI,RecordAll):-
	set(depthLimit,DepthLimit),
	EIs=[EI],
	findall(OneTr,
		(
		multi_gEx(DepthLimit,EIs,OneTr0),
		OneTr0=OneTr %remove_duplicates(OneTr0,OneTr)
		%, tInterpreter(OneTr,T),
		%nl,nl,write(OneTr),nl,	% track the ID of clauses in B
		%print_list(T),nl,nl
		),
		RecordAll).


/*************** All Examples (Single-Example Seed) ***************/
all_singleEIs(_,[],[]).
all_singleEIs(DepthLimit,[EI|EIs],[EI-Ts|AllT]):-
	all_singleEIs(DepthLimit,EIs,AllT),
	singleE(DepthLimit,EI,Ts).

% index the candidates
genAll([],[],1).
genAll([EI|EIs],[Ts|RestTs],Total):-
	genAll(EIs,RestTs,Pre),
	singleE(EI,Ts),
	%remove_duplicates(Ts0,Ts),
	length(Ts,TsNum),
	indexEI_CadidateHs(EI,Ts,TsNum),
	write('%***TRACE each time'),write({EI,TsNum}),nl,nl,
	Total is Pre*TsNum.


indexEI_CadidateHs(EI,[],0).
indexEI_CadidateHs(EI,[T|Ts],Index):-
	portray_clause(candidateH0(EI,Index,T)),
	PreIndex is Index-1,
	indexEI_CadidateHs(EI,Ts,PreIndex).
	
	

/*
indexEI_CadidateHs(EI,[],0).
indexEI_CadidateHs(EI,[T|Ts],Index):-
	indexEI_CadidateHs(EI,Ts,PreIndex),
	Index is PreIndex + 1,
	portray_clause(candidateH0(EI,Index,T)).
*/


/*candidateH(EI,Index,T):-
	candidateH0(EI,Index,T0),
	maplist(usedRuleRemoved,T0,T).*/

usedRuleRemoved([rs-{ReactionID,LimitingType,State,UsedRule,Time}],[rs-{ReactionID,LimitingType,State,Time}]).


%---------- signed here means each T is signed with EI
genAll_EIsigned([],[],1).
genAll_EIsigned([EI|EIs],[EI-Ts|RestTs],Total):-
	genAll_EIsigned(EIs,RestTs,Pre),
	set(depthLimit,DepthLimit),
	singleE(DepthLimit,EI,Ts0),	
	Ts=Ts0, %remove_duplicates(Ts0,Ts),
	length(Ts,K),
	write('***TRACE each time'),write({EI,K}),nl,
	Total is Pre*K.


genAll_signedTIs([],[],1).
genAll_signedTIs([EI|EIs],[EI-TIs|RestEITIs],Total):-
	genAll_signedTIs(EIs,RestEITIs,Pre),
	set(depthLimit,DepthLimit),
	singleE(DepthLimit,EI,Ts),
	%remove_duplicates(Ts0,Ts),
	length(Ts,TsNum),
	indexEI_CadidateHs(EI,Ts,TsNum),
	write('%***TRACE each time'),write({EI,TsNum}),nl,nl,
	numbersList(1,TsNum,TIs),
	Total is Pre*TsNum.



/*************** All Examples (Multi-Example Seed) ***************/
% The input
all_multiEIs(_,[],[]).
all_multiEIs(DepthLimit,[PairedEIs|AllEIs],[PairedEIs-Ts|AllT]):-
	all_multiEIs(DepthLimit,AllEIs,AllT),
	multiE(DepthLimit,PairedEIs,Ts).










